# -*- coding:utf8 -*-
import os
from flask import Flask
from ext import db
from config import config


def create_app(config_name, config_path=None):
    """工厂函数"""
    app = Flask(__name__)

    # 识别配置文件
    app.config.from_object(config[config_name])

    # 注册扩展
    register_extensions(app)
    return app


def register_extensions(app):
    """注册扩展"""
    # 数据库注册
    db.init_app(app=app)
